package com.biz.primus.ms.coupon.api;

import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.model.coupon.vo.couponType.*;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.coupon.service.CouponTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 优惠券类型Controller
 *
 * @author david-liu
 */
@Api(value = "/soa/couponType", description = "操作优惠券类型")
@RestController
@RequestMapping(value = "/soa/couponType")
public class CouponTypeApiController extends BaseApiController {

    @Autowired
    private CouponTypeService couponTypeService;

    @ApiOperation(value = "创建优惠券类型", notes = "创建优惠券类型")
    @PostMapping(value = "/createCouponType")
    public Boolean createCouponType(@ApiParam @RequestBody CouponTypeVo vo) {
        vo.validate();
        return couponTypeService.createCouponType(vo);
    }

    @ApiOperation(value = "获取优惠券类型列表", notes = "获取优惠券类型列表")
    @GetMapping(value = "/listCouponTypes")
    public SpringPageVO<CouponTypeDetailVo> listCouponTypes(
            @RequestParam(name = "name") String name,
            @RequestParam(name = "page", defaultValue = "0") int page,
            @RequestParam(name = "pageSize", defaultValue = "50") int pageSize
    ) {
        return couponTypeService.couponTypes(name, page, pageSize);
    }

    @ApiOperation(value = "更新优惠券类型", notes = "更新优惠券类型")
    @PostMapping(value = "/updateCouponType")
    public Boolean updateCouponType(@RequestParam(name = "couponTypeId") Long couponTypeId, @ApiParam @RequestBody CouponTypeVo vo) {
        vo.validate();
        return couponTypeService.updateCouponType(couponTypeId, vo);
    }

    @ApiOperation(value = "更新优惠券类型基本信息", notes = "更新优惠券类型基本信息")
    @PostMapping(value = "/updateCouponTypeInfo")
    public Boolean updateCouponTypeInfo(@RequestParam(name = "couponTypeId") Long couponTypeId, @ApiParam @RequestBody UpdateCouponTypeInfoReqVo reqVo) {
        reqVo.validate();
        return couponTypeService.updateCouponTypeBaseInfo(couponTypeId, reqVo);
    }

    @ApiOperation(value = "删除优惠券类型", notes = "删除优惠券类型")
    @PostMapping(value = "/deleteCouponType")
    public Boolean deleteCouponType(@RequestParam(name = "couponTypeId") Long couponTypeId, @RequestParam(name = "deleteUser") String deleteUser) {
        return couponTypeService.deleteCouponType(couponTypeId, deleteUser);
    }

    @ApiOperation(value = "更新优惠券启用禁用状态", notes = "更新优惠券启用禁用状态")
    @PostMapping(value = "/updateCouponTypeStatus")
    public Boolean updateCouponTypeStatus(@RequestBody UpdateCouponTypeStatusReqVo reqVo) {
        reqVo.validate();
        return couponTypeService.updateCouponTypeEnableStatus(reqVo.getCouponTypeIds(), reqVo.getStatus());
    }

    @ApiModelProperty(value = "追加发行优惠券数量", notes = "追加发行优惠券数量")
    @PostMapping(value = "/appendCouponTypeIssuedCount")
    public Boolean appendCouponTypeIssuedCount(@RequestBody AppendCouponTypeIssuedCountVo vo) {
        vo.validate();
        return couponTypeService.appendCouponTypeIssuedCount(vo);
    }
}
